//创建切片
import { createSlice,createAsyncThunk }  from '@reduxjs/toolkit'
import {findById} from "../../services/user"


export  const fetchUser=createAsyncThunk("user/fetchUser",async(id)=>{
    let res=await findById(id)
    return res
})

const userSlice=createSlice({
    name:"user",
    initialState: {
        updateVisible: false,
        updateuser: {},
    },
    reducers:{
        //创建命令名
        setUpdateVisible(state,action){
            state.updateVisible=action.payload
        },
        // setUpdateuser(state,action){
        //     state.updateuser=action.payload
        // }
    },
    extraReducers(builder){
        builder.addCase(fetchUser.fulfilled,(state,action)=>{
            state.updateuser=action.payload
        })
    }
})
export const {setUpdateVisible}=userSlice.actions;
export default userSlice.reducer